package com.woniuxy.controller;

import com.woniuxy.entity.Admin;
import com.woniuxy.service.AdminService;
import com.woniuxy.util.Result;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class AdminController {
    @Resource
    private AdminService adminService;
    @RequestMapping("/login")
    public Result login(String name,String password,Boolean remenberMe) throws Exception{
        Subject subject = SecurityUtils.getSubject();
        if(!subject.isAuthenticated()){
            UsernamePasswordToken token = new UsernamePasswordToken(name, password, remenberMe);
            subject.login(token);
        }
        Admin admin = (Admin)subject.getPrincipal();
        return new Result("200","success",admin,null);
    }
    @RequestMapping("/selectAdmin")
    public Result selectAdmin() throws Exception{
        Subject subject = SecurityUtils.getSubject();
        Admin admin = (Admin)subject.getPrincipal();
        return new Result("200","success",admin,null);
    }
}
